package engineer;

import entity_model.data_types.DataType;
import mysql.types.Type;

import java.util.LinkedHashMap;
import java.util.Map;

import static entity_model.data_types.DataTypes.*;
import static mysql.types.Types.BIT;
import static mysql.types.Types.INT;
import static mysql.types.Types.VARCHAR;

/**
 * Created by nuno-rafael-figueiredo on 02-07-2014.
 */
public class TypeMapper {
    public static final Map<DataType, Type> MYSQL_TYPES = new LinkedHashMap<>();
    public static final Map<Type, DataType> DATA_TYPES = new LinkedHashMap<>();

    static {
        put(ALPHANUMERIC_STRING, VARCHAR);
        put(BOOLEAN, BIT);
        put(CHARACTERS, VARCHAR);
        put(INTEGER, INT);
    }

    private static void put(DataType dataType, Type type) {
        MYSQL_TYPES.put(dataType, type);
        DATA_TYPES.put(type, dataType);
    }

    public static Type toMySQL(DataType dataType) {
        return MYSQL_TYPES.get(dataType);
    }

    public static DataType toDataType(Type type) {
        return DATA_TYPES.get(type);
    }
}
